package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import okhttp3.internal.tls.OkHostnameVerifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: baseTrademarkController
 * @Author: WDD
 * @CreateTime: 2022-12-01  22:23
 * @Description:
 */
@Api(tags = "品牌列表管理")
@RestController
@RequestMapping("/admin/product/")
public class baseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    @ApiOperation("获取品牌分页列表")
    @GetMapping("baseTrademark/{page}/{limit}")
    public Result page(@PathVariable("page") Long page,@PathVariable("limit") Long limit){
        Page<BaseTrademark> trademarkPage = new Page<>(page, limit);
        Page<BaseTrademark> baseTrademarkPage = baseTrademarkService.page(trademarkPage);
        return Result.ok(baseTrademarkPage);
    }

    @ApiOperation("根据id查询品牌")
    @GetMapping("baseTrademark/get/{id}")
    public Result findById(@PathVariable("id") Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation("添加品牌")
    @PostMapping("baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌")
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result remove(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("修改品牌")
    @PutMapping("baseTrademark/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("获取品牌属性")
    @GetMapping("baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> trademarkList = baseTrademarkService.list();
        return Result.ok(trademarkList);
    }
}
